package com.yuma.advisor.controller;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.SimpleLoggerAdvisor;
import org.springframework.ai.ollama.OllamaChatModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class AdvisorController {

    ChatClient chatClient;

    public AdvisorController(@Autowired OllamaChatModel ollamaChatModel) {
        chatClient = ChatClient.builder(ollamaChatModel)
                .defaultSystem("你是一个助手，请直接回答问题，不要输出任何推理过程或解释。")
                .defaultAdvisors(
                        new SimpleLoggerAdvisor()
                )
                .build();
    }
    @GetMapping("/loggerAdvisor")
    public String testChatOptions() {
        String content = chatClient.prompt()
                .user("你好")
                .call()
                .content();
        return content;
    }

    @GetMapping("/reReadAdvisor")
    public String reReadAdvisor() {
        return chatClient.prompt()
                .user("人活着的意义是什么？")
                .advisors(new ReReadingAdvisor())
                .call()
                .content();
    }

    @GetMapping("/memory")
    public String memoryTest() {
        chatClient.prompt()
                .user("我叫御码 ")
                .call()
                .content();

        return chatClient.prompt()
                .user("我叫什么")
                .call()
                .content();
    }
}
